﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Web.Library.DomainObject.SQLServer;

namespace Web.Library.Facade.SQLServer
{
    public partial class SysUserFacade 
    {
        public bool ValidateUser(string usercode, string password, out SysUser user)
        {
            return dal.ValidateUser(usercode, password, out user);
        }

        public virtual List<SysUser> GetListMore(int pageSize, int currentPage, string sortName, string sortOrder)
        {
            return dal.GetListMore(pageSize, currentPage, sortName, sortOrder);
        }

        public virtual List<SysUser> GetListMoreTable(int pageSize, int currentPage, string sortName, string sortOrder)
        {

            List<SysUser> users = dal.GetList(pageSize, currentPage, sortName, sortOrder);

            users.ForEach(delegate(SysUser user)
            {
                user.Groups = new Lazy<SysGroups>(()=>dal.LoadGroups(Convert.ToInt32(user.GroupID)));
                //user.GroupsApplication = new Lazy<SysApplicationGroups>(()=>dal.LoadGroupApp(Convert.ToInt32(user.GroupAppID)));
            });

            return users;

            //ProductsRepo dal = new ProductsRepo(connectionString);

            //products.ForEach(delegate(Products product)
            //{
            //    product.Categories = new Lazy<Categories>(() => dal.LoadCategory(product.CategoryID, connectionString));
            //    product.Suppliers = new Lazy<Suppliers>(() => dal.LoadSupplier(product.SupplierID, connectionString));
            //});

            //return products;

           // return users;
        }

        public bool UpdateProfile(SysUser domain)
        {
            return dal.UpdateProfile(domain);
        }

        public bool UpdateResetPassword(SysUser domain)
        {
            return dal.UpdateResetPassword(domain);
        }
    }
}
